package router

import (
	jwt "gitee.com/sansaniot/ssiot-core/httpmvc/jwtauth"
	"github.com/gin-gonic/gin"
)

var (
	RouterNoCheckRole = make([]func(*gin.RouterGroup), 0)
	RouterCheckRole   = make([]func(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware), 0)
)

func InitRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {

	// 无需认证的路由
	noCheckRoleRouter(r)
	// 需要认证的路由
	checkRoleRouter(r, authMiddleware)

	return r
}

// 无需认证的路由示例
func noCheckRoleRouter(r *gin.Engine) {
	// 可根据业务需求来设置接口版本
	//v1 := r.Group("/api")
	v1 := r.Group("")
	for _, f := range RouterNoCheckRole {
		f(v1)
	}
}

// 需要认证的路由示例
func checkRoleRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) {
	// 可根据业务需求来设置接口版本
	//v1 := r.Group("/api")
	v1 := r.Group("")
	for _, f := range RouterCheckRole {
		f(v1, authMiddleware)
	}
}
